Many of today's data processing systems utilize interrupts. Interrupts are well known in the art of data processing systems.
There are a wide variety of ways in which interrupts can be used. One common way in which interrupts are used is for real-time processing in a microprocessor system. For example, in a microprocessor system, a timer may send an interrupt request to a central processing unit (CPU) in order to indicate that a particular time event has occurred. After receiving the interrupt and determining that it should act upon the interrupt, the CPU may stop its normal non-interrupt processing and switch to interrupt processing.
In most microprocessor systems, the CPU receives an interrupt vector which the CPU loads into its program counter register. The CPU then begins executing the software interrupt service routine which begins at the memory location pointed to by the interrupt vector. In the timer example, the interrupt service routine may be as simple as a software routine which updates the display of a digital clock after each second. Or the interrupt service routine may be as complex as a software routine which calculates the required spark timing in an automobile engine.
One of the drawbacks to using interrupts in a microprocessor system is the overhead time that is required in order to stack register values onto a memory stack. When a register value is "stacked" or "pushed onto the stack", the register value is transferred from its register and written into a memory location. The stacking of registers is usually required in order to preserve the original register values. Because an interrupt service routine may modify one or more of the original register values, the original register values are temporarily stored in a readable and writeable memory. Random Access Memory (RAM) is often used as the "memory stack" or "stack", but other types of temporary storage may also be used.
Once the interrupt service routine has completed, normal, non-interrupt processing can continue and the original register values can be "unstacked" or "pulled off of the stack". When a register value is "unstacked", the register value is retrieved from the memory stack and transferred back into its respective register.
Some simple microprocessors (such as the MC68HC11 family of microprocessors, available from Motorola, Inc. of Austin, Tex.), merely stack all of the register values, except for the stack pointer register value. The value stored in the stack pointer register is not stacked because it is used to continuously point to whichever entry in the stack is available next. The value stored in the stack pointer register is also called the "stack pointer".
The stack pointer in the MC68HC11 family of microprocessors can be changed in several ways. First, the user, in software, can initiate an instruction which causes a specified value to be loaded into or written into the stack pointer register. In normal operation, the user does not usually change the stack pointer in this manner except to initially set the stack pointer to a value which points to the beginning of the stack.
Although the beginning of the stack may be anywhere within the memory space of the stack, most stacks either start at the lowest address and fill toward the highest address, or else start at the highest address and fill toward the lowest address. In addition, some stacks automatically wrap around from the highest address to the lowest address and/or from the lowest address to the highest address. The MC68HC11 family of microprocessors uses a stack which fills from higher addresses to lower addresses.
The second way in which the stack pointer in the MC68HC11 family of microprocessors can be changed is by a stacking or unstacking operation. Every time that a register value is stacked or unstacked from the memory stack, the stack pointer must be automatically updated by the internal microprocessor circuitry so that the stack pointer continues to point to whichever entry in the stack is available next.
The stack pointer may point to whichever entry in the stack is available next in one of several ways. First, the stack pointer may point directly to the next stack location to be accessed for a stacking operation. For example, if the stack fills from higher addresses to lower addresses and the stack pointer is $06, a stacking operation will access memory location $06, whereas an unstacking operation will access memory location $07.
Alternatively, the stack pointer may point directly to the next stack location to be accessed for an unstacking operation. For example, if the stack fills from higher addresses to lower addresses and the stack pointer is $06, a stacking operation will access memory location $05, whereas an unstacking operation will access memory location $06. In the present MC68HC11 family of microprocessors, the stack pointer is the 16-bit address of the next stack location to be accessed for a stacking operation.
In the present MC68HC11 family of microprocessors, each time that a byte is pushed onto the stack, the stack pointer is always automatically decremented by the internal microprocessor circuitry. Likewise, each time that a byte is pulled off of the stack, the stack pointer is always automatically incremented by the internal microprocessor circuitry. Thus the stack pointer is not changed in the present MC68HC11 family of microprocessors, except in the following circumstances: a stacking operation, an unstacking operation, a write access by the user, instructions which increment and decrement the stack pointer, and instructions which transfer the contents of an index register to the stack pointer.
In the present MC68HC11 family of microprocessors, the stack is most commonly used for interrupt processing, for subroutine calls, and for temporary storage of data values. However, regardless of the reason for a stacking operation or an unstacking operation, the stack pointer is always concurrently incrementally adjusted (i.e. by incrementing or decrementing) so that the stack pointer value continues to point to a next available entry in the stack.
Again, one of the drawbacks to using interrupts in a microprocessor system is the overhead time that is required in order to stack register values onto a memory stack. In some microprocessor applications, such as certain controller applications, many operations are performed using interrupt service routines. Thus interrupts may occur very frequently in some applications. Unfortunately, in the present MC68HC11 family of microprocessors, all of the registers except for the stack pointer register are automatically stacked whenever the CPU determines that a pending interrupt is to be processed. Thus a great deal of processing time may be spent repeatedly stacking and unstacking register values each time that an interrupt is processed.